// JavaScript Document
$(document).ready(function(){

	var winWidth = $(window).width();
	if (winWidth > 1024){
		//$('.container').width(960);
	}
	else {
		$('.container').css('padding', '0 10px');
	}
	
	if (($.browser.msie) && ($.browser.version <= "9.0")) {
	 $('.top-bar form input[type=text]').val('Search...');
	 $('.top-bar form input[type=text]').focus(function(){
				if($(this).val() == 'Search...' ){
					$(this).val('');
				}	
			});
	$('.top-bar form input[type=text]').blur(function(){
				if($(this).val() == '' ){
					$(this).val('Search...');
				}
	});
	}
	
	// ----------------------------------------------
	$('.nav li, .third-col li').addClass('clearfix');
	$('.table tr:odd td').css('background', '#f2f2f2');
	$('.research-accordion li:odd').css('background', '#f5f5f5');
	$('.side-list li').has('ul').css('padding-bottom', '0');
	
	// ----------------------------------------------
	$('.third-col li, .research-accordion li .links a, .related-links li').prepend('<span class="icon">&rarr;</span>');
	$('.content-block ul li, .list-links li').prepend('<span class="icon"></span>');
	$('.sitemap li li, .sitemap li li li, .not_found li').prepend( $( "<span class='icon'></span>" ) );
	$( ".third-col li, .content-block ul li, .research-accordion li .links a, .related-links li, .list-links li" ).wrapInner( "<div class='text'></div>");
	$('.third-col li span.icon, .content-block ul li span.icon, .list-links li span.icon, .research-accordion li .links a span.icon, .related-links li span.icon').each(function() {
		$(this).parent().before(this);
	});
	
	// ----------------------------------------------
	var homeSections = $('.home-content').height();
	$('.first-col, .second-col, .third-col').height(homeSections-45);
	
	var innerSections = $('.inner-content').height();
	$('.left-side, .right-side').height(innerSections+50);
	
	/*var leftHeight = $('.left-side').height();
	var rightHeight = $('.right-side').height();
	
	if (leftHeight > rightHeight) {
		$('.right-side').height(leftHeight);
	}
	
	else if (leftHeight < rightHeight) {
		$('.left-side').height(rightHeight);
	}*/
	
	// ===========================================================
	$(function(){
		$('.action').click(function(){
			$(this).parent('.research-accordion li').parent('ul.research-accordion').css('margin-bottom', '0');
			$('.links').each(function(index, element) {
                    $(this).slideUp();
                });
				
				$('.research-accordion li').each(function(index, element) {
                    $(this).removeClass('open');
                });
				
				if(($(this).next('.links').css('display') == 'none')) {
					$(this).next('.links').slideToggle();
					$(this).parent('.research-accordion li').addClass('open');
				}
				
			});
	});
	
			
			
			
			// accordion ---------------------------------------------------------
	
	
	
	
	$('.vacancy_title').click(function(){
			$('.vacancy_details').each(function(index, element) {
                    $(this).slideUp();
                });
				
				$('.vacancy').each(function(index, element) {
                    $(this).removeClass('open');
                });
				
				if(($(this).next('.vacancy_details').css('display') == 'none')) {
					$(this).next('.vacancy_details').slideToggle();
					$(this).parent('.vacancy').addClass('open');
				}
			});
			
			
			
			
			// to top 
			
			
	
	$('.to-top').click(function(){
				$('html, body').animate({
					scrollTop: $(".inner-content h2").offset().top
				}, 700);
			});
			
			
	
	
});


$(window).load(function(){
      $('.home-slider').flexslider({
        animation: "fade",
		slideshow: true,
		directionNav: false,
        start: function(slider){
          $('body').removeClass('loading');
        }
      });
    });
	
$(window).load(function() {
		// top 
        $('.news-block:even p').each(function(index, element) {
            if ( $(this).children('i').length > 0 ) {
				$(this).children('i').css({float: 'right', marginRight: '0', marginLeft: '24px'});
				
		}
		else{
			$(this).children('span').css('width', 'auto');
		}
        });
		
		// bottom 
		$('.news-block:odd p').each(function(index, element) {
			if ( $(this).children('i').length > 0 ) {
				
				$(this).children('span').css({width: '435px'});
		}
		else{
			
			//$('.news-block:odd h4').css({float: 'left', width: 'auto'});
			$(this).children('span').css({width: 'auto'});
		}
		});
		
		$('.news-block p').each(function(){
			var y = $(this).width();
			var x = $(this).children('i').children('img').width()+26;
			$(this).children('.news-block p i + span').width(y-x);
			$(this).children('i').width($(this).children('i').children('img').width()+2);
			
			// console.log("image width" +'\n' + x);
			
			// console.log("paragraph" +'\n' + y);
		});
		
		$('.list-fake span.square').html('&#9642;');
    });